package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.DeviceInfo;
import com.ruoyi.system.service.IDeviceInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 设备基础信息管理Controller
 *
 * @author ruoyi
 * @date 2025-03-19
 */
@RestController
@RequestMapping("/system/info1")
public class DeviceInfoController extends BaseController {
    @Autowired
    private IDeviceInfoService deviceInfoService;

    /**
     * 查询设备基础信息管理列表
     */
    //@PreAuthorize("@ss.hasPermi('system:info1:list')")
    @GetMapping("/list")
    public TableDataInfo list(DeviceInfo deviceInfo) {
        startPage();
        List<DeviceInfo> list = deviceInfoService.selectDeviceInfoList(deviceInfo);
        return getDataTable(list);
    }

    /**
     * 导出设备基础信息管理列表
     */
    //@PreAuthorize("@ss.hasPermi('system:info1:export')")
    //@Log(title= "设备基础信息管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeviceInfo deviceInfo) {
        List<DeviceInfo> list = deviceInfoService.selectDeviceInfoList(deviceInfo);
        ExcelUtil<DeviceInfo> util = new ExcelUtil<DeviceInfo>(DeviceInfo.class);
        util.exportExcel(response, list, "设备基础信息管理数据");
    }

    /**
     * 获取设备基础信息管理详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:info1:query')")
    @GetMapping(value = "/{deviceId}")
    public AjaxResult getInfo(@PathVariable("deviceId") String deviceId) {
        return success(deviceInfoService.selectDeviceInfoByDeviceId(deviceId));
    }

    /**
     * 新增设备基础信息管理
     */
    //@PreAuthorize("@ss.hasPermi('system:info1:add')")
    //@Log(title= "设备基础信息管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeviceInfo deviceInfo) {
        return toAjax(deviceInfoService.insertDeviceInfo(deviceInfo));
    }

    /**
     * 修改设备基础信息管理
     */
    //@PreAuthorize("@ss.hasPermi('system:info1:edit')")
    //@Log(title= "设备基础信息管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeviceInfo deviceInfo) {
        return toAjax(deviceInfoService.updateDeviceInfo(deviceInfo));
    }

    /**
     * 删除设备基础信息管理
     */
    //@PreAuthorize("@ss.hasPermi('system:info1:remove')")
    //@Log(title= "设备基础信息管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{deviceIds}")
    public AjaxResult remove(@PathVariable String[] deviceIds) {
        return toAjax(deviceInfoService.deleteDeviceInfoByDeviceIds(deviceIds));
    }
}
